package com.ekang.admin.dao;

import com.ekang.admin.model.Member;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.StatementType;

import java.util.List;

/**
 * Created by admin on 2017/10/26.
 */
@Mapper
public interface MemberMapper {


    @Insert(
            "insert into `yun_member` (`username`,`password`,`email`,`moblie`,`regIp`,`regDate`,`loginIp`,`loginDate`,`userType`,`loginHits`,`salt`,`address`,`nameRepeat`,`qqid`,`status`,`pwuid`,`pwRepeat`,`lockInfo`,`emailStatus`,`signature`,`sinaid`,`wxid`,`wxOpenId`,`unionid`,`wxname`,`wxbindtime`,`passtext`,`source`,`regcode`,`did`,`claim`,`restname`,`appeal`,`appealTime`,`appealState`,`signday`,`signdays`,`xcxid`,`xcxname`,`xcxkey`,`lastUpdateTime`)\n" +
                    " values(#{m.username},#{m.password},#{m.email},#{m.moblie},#{m.regIp},#{m.regDate},#{m.loginIp},#{m.loginDate},#{m.userType},#{m.loginHits},#{m.salt},#{m.address},#{m.nameRepeat},#{m.qqid},#{m.status},#{m.pwuid},#{m.pwRepeat},#{m.lockInfo},#{m.emailStatus},#{m.signature},#{m.sinaid},#{m.wxid},#{m.wxOpenId},#{m.unionid},#{m.wxname},#{m.wxbindtime},#{m.passtext},#{m.source},#{m.regcode},#{m.did},#{m.claim},#{m.restname},#{m.appeal},#{m.appealTime},#{m.appealState},#{m.signday},#{m.signdays},#{m.xcxid},#{m.xcxname},#{m.xcxkey},#{m.lastUpdateTime})"
    )
    @Options(useGeneratedKeys = true, keyProperty = "m.uid")
    int insertMember(@Param("m") Member member);


    @Update({"<script>",
            "update yun_member <set> ",
            "<if test=\"m.status!=null and m.status!=''\">",
            "status=#{m.status}, </if>",
            "<if test=\"m.wxOpenId!=null and m.wxOpenId!=''\">",
            "wxOpenId=#{m.wxOpenId}, </if>",
            "<if test=\"m.lastUpdateTime!=null and m.lastUpdateTime!=''\">",
            "lastUpdateTime=#{m.lastUpdateTime}, </if>",
            "<if test=\"m.password!=null and m.password!=''\">",
            "password=#{m.password}, </if>",
            "<if test=\"m.username!=null and m.username!=''\">",
            "username=#{m.username}, </if>",
            "<if test=\"m.unionid!=null and m.unionid!=''\">",
            "unionid=#{m.unionid}, </if>",
            "<if test=\"m.wxOpenId!=null and m.wxOpenId!=''\">",
            "wxOpenId=#{m.wxOpenId}, </if>",
            "</set>",
            "where uid=#{m.uid} limit 1</script>"})
    int updatMember(@Param("m") Member member);


    @Select("select * from yun_member where uid=#{id}")
    Member getMemberById(@Param("id") Integer id);

    @Select("select * from yun_member where username=#{userName}")
    Member getMemberByName(@Param("userName") String userName);

    @Select("select * from yun_member where status>0 and userId=#{userId} order by  addTime desc")
    List<Member> getMemberList(@Param("userId") String userId);


    @Select("select * from yun_member where wxOpenId=#{openID} limit 1")
    Member getMemberByWxOpenID(@Param("openID") String openID);


}
